package hust.game.main;

import hust.game.asset.Assets;
import hust.game.asset.SpriteAccessor;
import hust.game.screen.SplashScreen;
import aurelienribon.tweenengine.Tween;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;

public class MainGame extends Game{
	private static MainGame instance;
	
	SplashScreen mSplashScreen;
	@Override
	public void create() {
		// TODO Auto-generated method stub
		instance = this;
		Tween.setWaypointsLimit(10);
		Tween.setCombinedAttributesLimit(3);
		Tween.registerAccessor(Sprite.class, new SpriteAccessor()); 
		
		Assets.inst().load("data/splash/splash.pack", TextureAtlas.class);
		Assets.inst().load("data/splash/loading.pack", TextureAtlas.class);
		Assets.inst().finishLoading();
		
		mSplashScreen = new SplashScreen(); 
		setScreen(mSplashScreen);
	}
	
	@Override
	public void render() {
		// TODO Auto-generated method stub
		super.render();
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		if (getScreen() != null) {
			getScreen().render(Gdx.graphics.getDeltaTime());
		}
		if (Assets.inst().getProgress() < 1) {
			Assets.inst().update();
		} 
	}

	public static MainGame getInstance() {
		return instance;
	}
}
